<?php

namespace YmPhp\Admin\Http\Controllers\SiteCity;

use YmPhp\Admin\Form;
use YmPhp\Admin\Grid;
use YmPhp\Admin\Http\Repositories\SiteCity;
use YmPhp\Admin\Show;
use YmPhp\Admin\Http\Controllers\AdminController;

class SiteCityController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SiteCity(), function (Grid $grid) {
            $grid->model()->orderByDesc('stid');
            $grid->column('stid')->sortable();
            $grid->column('area','城市名称')->display(function ($value) {
                if ($this->area3){
                    $areaList =  "<span >{$this->area3}</span>";
                }elseif ($this->area2){
                    $areaList =  "<span style='margin-bottom: 2px'>{$this->area2}</span>";
                }elseif ($this->area1){
                    $areaList =  "<span style='margin-bottom: 2px'>{$this->area1}</span>";
                }
                return $areaList;
            });
            $grid->column('icon')->image('',60);
            $grid->column('description');
            $grid->column('ratio')->editable(true)->append('%');
            $grid->column('stationmasterInfo','站长信息')->display(function () {
                if (empty($this->username)){
                    $html = '<small><a href="javascript:;"  class="link userinfo">暂无管理员</a></small><br>';
                }else{
                    $html = '<small>名称：<a href="javascript:;"  class="link userinfo">'.$this->username.'</a></small><br>';
                }

                if(!empty($this->uid)){
                    $html .= '<small>UID：<a href="javascript:;" class="link userinfo">'.$this->uid.'</a></small>';
                }

                return $html;
            });
            $grid->column('qr')->image('',60)->display(function () {
                if (empty($this->qr))
                    return '<span class="text-muted">暂无</span>';
                else
                return '<img src="'.$this->qr.'" width="60" height="60" />';
            });
            $grid->column('status')->using(['-1' => '未审核', '1' => '已上线', '0' => '下线中'])->label(['0' => 'default', '1' => 'success', '2' => 'danger']);

            $grid->disableCreateButton();
            $grid->disableEditButton();
            $grid->disableViewButton();
            $grid->showQuickEditButton();
            $grid->showQuickViewButton();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('stid');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SiteCity(), function (Show $show) {
            $show->field('stid');
            $show->field('name');
            $show->field('status');
            $show->field('icon');
            $show->field('description');
            $show->field('ratio');
            $show->field('uid');
            $show->field('username');
            $show->field('crts');
            $show->field('upts');
            $show->field('endts');
            $show->field('qr');
            $show->field('uid2');
            $show->field('hs_name');
            $show->field('hs_desc');
            $show->field('area1');
            $show->field('area2');
            $show->field('area3');
            $show->field('index_topad');
            $show->field('index_midad');
            $show->field('sh_topad');
            $show->field('color');
            $show->field('color_title');
            $show->field('doamin');
            $show->field('index_topad_lnk');
            $show->field('index_midad_lnk');
            $show->field('sh_topad_lnk');
            $show->field('showcnt');
            $show->field('displayorder');
            $show->field('index_topad_color');
            $show->field('cats');
            $show->field('name2');
            $show->field('nohhrate');
            $show->field('shprice');
            $show->field('szm');
            $show->field('ishot');
            $show->field('lat');
            $show->field('lng');
            $show->field('length');
            $show->field('tid');
            $show->field('joinprice');
            $show->field('sp_topad');
            $show->field('sp_topad_lnk');
            $show->field('sync_ids');
            $show->field('fenyong');
            $show->field('jiam_fenyong');
            $show->field('index_code1');
            $show->field('index_code2');
            $show->field('index_code3');
            $show->field('index_code4');
            $show->field('index_code5');
            $show->field('sharetitle');
            $show->field('poi_id');
            $show->field('addr');
            $show->field('newcp');
            $show->field('appname');
            $show->field('appid');
            $show->field('appsecert');
            $show->field('app_shid');
            $show->field('app_shkey');
            $show->field('hideshai');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SiteCity(), function (Form $form) {
            $form->display('stid');
            $form->text('name');
            $form->text('status');
            $form->text('icon');
            $form->text('description');
            $form->text('ratio');
            $form->text('uid');
            $form->text('username');
            $form->text('crts');
            $form->text('upts');
            $form->text('endts');
            $form->text('qr');
            $form->text('uid2');
            $form->text('hs_name');
            $form->text('hs_desc');
            $form->text('area1');
            $form->text('area2');
            $form->text('area3');
            $form->text('index_topad');
            $form->text('index_midad');
            $form->text('sh_topad');
            $form->text('color');
            $form->text('color_title');
            $form->text('doamin');
            $form->text('index_topad_lnk');
            $form->text('index_midad_lnk');
            $form->text('sh_topad_lnk');
            $form->text('showcnt');
            $form->text('displayorder');
            $form->text('index_topad_color');
            $form->text('cats');
            $form->text('name2');
            $form->text('nohhrate');
            $form->text('shprice');
            $form->text('szm');
            $form->text('ishot');
            $form->text('lat');
            $form->text('lng');
            $form->text('length');
            $form->text('tid');
            $form->text('joinprice');
            $form->text('sp_topad');
            $form->text('sp_topad_lnk');
            $form->text('sync_ids');
            $form->text('fenyong');
            $form->text('jiam_fenyong');
            $form->text('index_code1');
            $form->text('index_code2');
            $form->text('index_code3');
            $form->text('index_code4');
            $form->text('index_code5');
            $form->text('sharetitle');
            $form->text('poi_id');
            $form->text('addr');
            $form->text('newcp');
            $form->text('appname');
            $form->text('appid');
            $form->text('appsecert');
            $form->text('app_shid');
            $form->text('app_shkey');
            $form->text('hideshai');
        });
    }
}
